#coding:utf-8
from app import create_app, db
from app.models import User, Task

app = create_app()

app.app_context().push()
db.create_all()


def importUser(file):
    with open(file) as f:
        line = f.readline()
        xh = int(line[6:16])
        username = line[16:25].decode('utf-8')
        print(xh,username)
        u = User(xh,username,'123456',0)
        db.session.add(u)
        while line != '':
            line = f.readline()
            try:
                xh = int(line[3:13])
                username = line[13:22].decode('utf-8')
                print(xh,username)
                u = User(xh,username,'123456',0)
                db.session.add(u)
            except Exception as e:
                pass

            
            
# u = User(1604081000,u'普通学生','123456',0)
# db.session.add(u)
# db.session.commit()


if __name__ == '__main__':
    importUser('stu.csv')
    db.session.commit()
